#!/bin/sh
#
# Copyright (c) 2016 Lucky Byte, Inc.
#
# PostgreSQL archive_command 脚本
#

# 参数: 1 -> %p, 2 -> %f，%p 和 %f 分别代表路径和文件名
path=$1
file=$2

# 检查参数是否有效
if test "x$path" = "x" || test "x$file" = "x" ; then
    echo 'Archive Command missing arguments, please check ...'
    exit 0
fi

# 备份文件路径
archdir="/opt/backup/pgsql/archive"
mkdir -p $archdir

if test ! -f $archdir/$file ; then
    echo "Copy $path to $archdir/$file"
    cp $path $archdir/$file
    gzip $archdir/$file
else
    echo "File '$archdir/$file' exists, cann't overwrite."
fi
exit 0

